package com.controller.front_controller;


import com.mypg.Video;
import com.mypg.VideoHelper;
import com.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/front_video")
@Controller
public class FrontVideoController {

    @Autowired
    VideoService videoService;

    @RequestMapping("/change_video.do")
    @ResponseBody
    public List<Video> doChange_video(String video_class_sub){
        List<Video> videoList=videoService.selectVideoByVideo_class_sub(video_class_sub);
//        List<VideoHelper> videoHelperList=VideoHelper.changeVideoListToVideoHelperList(videoList);
        return videoList;
    }

    @RequestMapping("/videodetail_init.do")
    @ResponseBody
    public Video doVideodetail_init(int video_id){
        return videoService.selectVideoByVideo_id(video_id);
    }

    @RequestMapping("/video_relative_init.do")
    @ResponseBody
    public List<Video> doVideo_relatice_init(int video_id){
        String video_class=videoService.selectVideoByVideo_id(video_id).getVideo_class();
        List<Video> videoList=videoService.selectVideoByVideo_class_sub(video_class);
        for(int i=0;i<videoList.size();i++){
            if(videoList.get(i).getVideo_id()==video_id){
                videoList.remove(i);
                break;
            }
        }
        return videoList;
    }
}
